package com.lulu.baselib.dialog;

import android.view.View;
import android.widget.TextView;

import com.lulu.baselib.R;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Author: XuChang
 * Date: 2019/10/31 17:48
 * Email: 123286473@qq.com
 * Description:自定义弹窗
 * History:
 */
public class MyAlertDialog extends BaseDialogFragment {
    @BindView(R.id.tvConfirm)
    TextView tvConfirm;
    @BindView(R.id.tvCancel)
    TextView tvCancel;
    @BindView(R.id.tvMsg)
    TextView tvMsg;

    public interface CallBack {
        /**
         * 确认
         */
        void onConfirm(MyAlertDialog dialog);

        /**
         * 取消
         */
        void onCancel(MyAlertDialog dialog);
    }

    public static abstract class CallBackAdapter implements CallBack {
        public void onCancel(MyAlertDialog dialog) {
            dialog.dismiss();
        }
    }


    String title;
    String confirm;
    String cancel;
    CallBack mCallBack;

    public MyAlertDialog(String title, String confirm, String cancel, CallBack callBack) {
        this.mCallBack = callBack;
        this.title = title;
        this.confirm = confirm;
        this.cancel = cancel;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_alert;
    }

    @Override
    protected void initView(View view) {
        tvMsg.setText(title);
        tvConfirm.setText(confirm);
        tvCancel.setText(cancel);
    }

    @OnClick(R.id.tvConfirm)
    public void onConfirm() {
        dismiss();
        if (mCallBack != null) {
            mCallBack.onConfirm(this);
        }
    }

    @OnClick(R.id.tvCancel)
    public void onCancel() {
        dismiss();
        if (mCallBack != null) {
            mCallBack.onCancel(this);
        }
    }


//    private static class Builder {
//        //默认值
//        String confrim = "确认";
//        String cancel = "取消";
//        FragmentManager fragmentManager;
//
//        public Builder(FragmentManager fragmentManager){
//            this.fragmentManager = fragmentManager;
//        }
//
//        public static abstract class CallBackAdapter implements CallBack{
//
//            /**
//             * 取消
//             */
//            public void onCancel(){
//
//            }
//        }
//
//        public Builder setConfrim(String confrim){
//            this.confrim = confrim;
//            return this;
//        }
//
//        public Bu
//
//
//        public
//    }
//
//    public static Builder getBuilder(FragmentManager fragmentManager) {
//        return new Builder(fragmentManager);
//    }
}
